package internal

import (
	"time"

	"github.com/gin-gonic/gin"
)

type Model struct {
	ID       uint      `json:"id" gorm:"primaryKey"`
	CreateAt time.Time `json:"created_at" gorm:"column:created_at"`
	UpdateAt time.Time `json:"updated_at" gorm:"column:updated_at"`
	DeleteAt time.Time `json:"deleted_at" gorm:"index"`
}

type ResponseMsg struct {
	Code int         `json:"code"`
	Msg  string      `json:"msg"`
	Data interface{} `json:"data,omitempty"`
}

type ActionModel struct {
	Ctx *gin.Context
}

func (ac *ActionModel) Success(msg string, defaults ...interface{}) {
	var data interface{}
	if len(defaults) > 0 {
		data = defaults[0]
	}
	result := ResponseMsg{Code: 200, Msg: msg, Data: data}
	ac.Ctx.PureJSON(200, result)
}

func (ac *ActionModel) Fail(msg string) {
	result := ResponseMsg{Code: 400, Msg: msg}
	ac.Ctx.PureJSON(200, result)
}
